package com.hfh.jdbc;

import java.sql.*;
import java.util.ResourceBundle;

/**
 * @Author hfh
 * @Date 2022 09 17 19 43
 **/
public class JDBCTest1 {
    public static void main(String[] args) {
        ResourceBundle bundle = ResourceBundle.getBundle("jdbc");
        String driver = bundle.getString("driver");
        String url = bundle.getString("url");
        String user = bundle.getString("user");
        String password = bundle.getString("password");

        Connection conn = null;
        Statement stmt = null;
        ResultSet rs = null;
        try {
            Class.forName(driver);

            conn = DriverManager.getConnection(url,user,password);
            System.out.println(conn);

            stmt = conn.createStatement();

            String sql = "select * from emp";
            rs = stmt.executeQuery(sql);
            while (rs.next()){
                System.out.println(rs.getString(1)+" "+rs.getString(2)+" "+rs.getString(3)+" "+
                        rs.getString(4)+" "+rs.getString(5)+" "+rs.getString(6)+" "+
                        rs.getString(7));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }finally {
            try {
                if(rs!=null){
                    rs.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                if(stmt!=null){
                    stmt.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
            try {
                if(conn!=null){
                    conn.close();
                }
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }

    }
}
